import apis from "@/api/apis.js"

export default{
	namespaced: true,
	state:{
		page:1,
		size:10,
		list:[],
		detailData:[],
		isHotData:[],
		sixTiemData:[],
		threeTiemData:[],
		oneTiemData:[],
		
	},
	mutations:{
		setRegularData(state,newData){
			state.list =newData;
			const isHots = newData.filter(item => {
				return item.isHot == "1"
			});
			// "10天", "7周", "11天"
			const sixTiem = newData.filter(item => {
				return item.periodTime == "2月" || item.periodTime =="10天"  || item.periodTime =="7周" || item.periodTime =="11天"
			});
			const threeTiem = newData.filter(item => {
				return item.periodTime == "100天"|| item.periodTime == "3月" || item.periodTime == "2月" 
			});
			const oneTiem = newData.filter(item => {
				return item.periodTime == "1年"
			});
			state.isHotData =isHots;
			state.sixTiemData =sixTiem;
			state.threeTiemData =threeTiem;
			state.oneTiemData =oneTiem;
		},
		setDetailData(state,newData){
			state.detailData = newData
			
		}
	},
	actions:{
		async getRegular(context){
			const data = await apis.regular.getRegular({
				page:context.state.page,
				size:context.state.size
			});
			if(data.code == 200){
				context.commit('setRegularData',data.data.list)
				
			}
		},
		async getDetailData(context,fid){
			const data = await apis.regular.getDetail(fid);
			if(data.code == 200){
				context.commit('setDetailData', data.data)
			}
		}
	}
}